package com.inlycat.web.intercepor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.inlycat.service.CodeService;
import com.inlycat.utils.Constant;

/**
 * @author jarvan4dev@163.com
 * @since 2015年8月28日下午3:36:00
 * @category 验证码拦截器
 **/
public class InviteInterceptor extends HandlerInterceptorAdapter {

	@Resource
	private CodeService codeService;

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {

		String code = request.getParameter("code").toUpperCase();
		
		boolean result = codeService.valid(code);
		if (result == false) {
			response.setStatus(Constant.FORBIDDEN);
		}
		/**
		 * 删除邀请码
		 */
		codeService.delete(code);
		//System.out.println(code);
		return result;
	}

}
